package 注解作用.test01;

import java.lang.reflect.Field;

public class Test01 {
    public static void main(String[] args) {
        Class userClass = User.class;
        if (userClass.isAnnotationPresent(Id.class)){
            Field[] userField = userClass.getDeclaredFields();
            boolean isRight = false;
            for (Field field : userField){
                if ("id".equals(field.getName()) && "int".equals(field.getType().getSimpleName())){
                    isRight = true;
                    break;
                }
            }
            if (!isRight){
                throw new HasNotIdPropertyException("被@Id注解标注的类中必须要有一个int类型id属性！");
            }
        }
    }
}
